package zjh_20230313;


import java.util.*;

public class practise {
    public static void main(String[] args) {
        test02();
    }

    public static void test() {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        for (String str : list) {
            System.out.print(str + " ");
        }
        list.remove(0);
        list.remove(list.size() - 1);
        Iterator it = list.iterator();
        while (it.hasNext()) {
            System.out.print(it.next() + ",");
        }
        System.out.println();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入插入第一个元素：");
        list.add(0, scanner.next());
        System.out.println("请输入插入第二个元素：");
        list.add(list.size(), scanner.next());
        for (String str :
                list) {
            System.out.println(str);
        }
    }
    public static void test02(){
        List list = List.of("Zhou","Wang","Zhang");
        LinkedList<String> list1 = new LinkedList<>(list);
        for (String s :
                list1) {
            System.out.print(s + "  ,   ");
        }
        System.out.println();
        list1.removeFirst();
        list1.removeLast();
        for (String s :
                list1) {
            System.out.print(s + "  ,   ");
        }
        System.out.println();
        list1.addFirst("1");
        list1.addLast("2");
        for (String s :
                list1) {
            System.out.print(s + "  ,   ");
        }
        System.out.println();
    }

}
